package com.xoa.controller.party;


import com.xoa.model.party.GridEvent;
import com.xoa.service.document.DocumentSerivce;
import com.xoa.service.party.GridEventService;
import com.xoa.util.ToJson;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.common.wrapper.BaseWrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;

/**
 * Created by gsb on 2017/9/6.
 */
@RestController
@RequestMapping("/gridEvent")
public class GridEventController {
    @Autowired
    private GridEventService gridEventService;

    /**
     * 代办
     * @param request
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("/selWillGridSendOrReceive")
    public BaseWrappers selWillDocSendOrReceive(HttpServletRequest request, String eventType,
                                                @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                                @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize
    ) {
        return gridEventService.selWillGridSendOrReceive(request,eventType, page, pageSize, DocumentSerivce.PRCS_FLAG_WILL, DocumentSerivce.PRCS_FLAG_WILL);
    }
    /**
     * 已办
     * @param request
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("/selWillGridOpenOrReceive")
    public BaseWrappers selWillGridOpenOrReceive(HttpServletRequest request, String eventType,
                                                 @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                                 @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize
    ) {
        return gridEventService.selWillGridSendOrReceive(request,eventType ,page, pageSize, DocumentSerivce.PRCS_FLAG_OVER, DocumentSerivce.PRCS_FLAG_WILL);
    }

    /**
     * 添加
     * @param gridEvent
     * @return
     */
    @RequestMapping("/addGridEvent")
     public BaseWrapper addGridEvent(GridEvent gridEvent, String dateTime) {
        gridEvent.setEventParting("1");
        return gridEventService.addGridEvent(gridEvent,dateTime);
    }
    /**
     * 列表
     * @param request
     * @param page
     * @param pageSize
     * @param flowStatus
     * @return
     */
    @RequestMapping("/selectbYfLOWstuts")
    public BaseWrappers selectbYfLOWstuts(HttpServletRequest request, boolean useFlag, Integer page, Integer pageSize, String flowStatus
    ) {
        return gridEventService.selectbYfLOWstuts(request,useFlag,page,pageSize,flowStatus, DocumentSerivce.PRCS_FLAG_WILL);
    }
    @RequestMapping("/selectGridEvent")
    public BaseWrappers selectGridEvent(HttpServletRequest request, HttpServletResponse response, Integer page, Integer pageSize, String userId,
                                        String gridId, String exentType, String flowStatus, String beginDate, String endDate, String exportId){
  return gridEventService.selectGridEvent(request,response,page,pageSize,userId,gridId,exentType,flowStatus,beginDate,endDate,exportId, DocumentSerivce.PRCS_FLAG_WILL);
    }


    @RequestMapping("/getStatistics")
    public BaseWrappers checkStatistics(String timeType, String queryType) {
        return gridEventService.getStatistics(timeType,queryType, DocumentSerivce.PRCS_FLAG_WILL);
    }

    @RequestMapping("/checkStatisticsAtui")
    public ToJson checkStatisticsAtui(String timeType, Integer parting, Integer flowId) {
        return gridEventService.getStatistics(timeType,parting,flowId);
    }

    @RequestMapping("/selectByPrimaryKey")
    public BaseWrapper selectByPrimaryKey(Integer eventId, HttpServletRequest request) {
        return gridEventService.selectByPrimaryKey(eventId,request);
    }
    @RequestMapping("/deleteByPrimaryKey")
    public BaseWrapper deleteByPrimaryKey(Integer eventId) {
        return gridEventService.deleteByPrimaryKey(eventId);
    }
    @RequestMapping("/updateByPrimaryKeySelective")
    public BaseWrapper updateByPrimaryKeySelective(GridEvent gridEvent, String dateTime) {
        gridEvent.setEventParting("1");
        return gridEventService.updateByPrimaryKeySelective(gridEvent,dateTime);
    }
    @RequestMapping("/getCountByname")
    public BaseWrappers getCountByname(String timeType) {
        return gridEventService.getCountByname(timeType, DocumentSerivce.PRCS_FLAG_WILL);
    }

    @ResponseBody
    @RequestMapping("/getLastEventMsg")
    public BaseWrappers getLastEventMsg(){
        return gridEventService.getLastEventMsg();
    }


    @RequestMapping("/selecTd")
    public BaseWrappers selecTd(HttpServletRequest request, String timeUser) {
        return gridEventService.selecTd(request,timeUser);
    }

    @RequestMapping("/selectEventWyhwg")
    @ResponseBody
    public ToJson selectEventWyhwg(Integer eventId){
            return  gridEventService.selectEventWyhwg(eventId);
    }

    /**
     * 指派统计
     * @param timeType
     * @param queryType
     * @param startTime
     * @param endTime
     * @param request
     * @return
     */
    @RequestMapping("/getStatisticsByGridType")
    public BaseWrappers getStatisticsByGridType(String timeType, String queryType, String startTime, String endTime, HttpServletRequest request, String typeDate){
        return  gridEventService.getStatisticsByGridType(timeType,queryType,startTime,endTime,request);
    }

    @RequestMapping("/getStatisticsByGridEventType")
    public BaseWrappers getStatisticsByGridEventType(String timeType, String queryType, String startTime, String endTime, HttpServletRequest request, String typeDate){
        return  gridEventService.getStatisticsByGridEventType(timeType,queryType,startTime,endTime,request,typeDate);
    }
    @RequestMapping("/gridByUserName")
    public BaseWrappers gridByUserName(String userName, String location, String gridId, String type, String timeType,
                                       @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                       @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize){
        return  gridEventService.gridByUserName(userName,location,page,pageSize,gridId,type,timeType);
    }

    @RequestMapping("/gridEventByUserName")
    public BaseWrappers gridEventByUserName(String timeType, String startTime, String endTime, String userName, String location, String gridId, String type,
                                            @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                            @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize){
        return  gridEventService.gridEventByUserName(timeType,startTime,endTime,userName,location,page,pageSize,gridId,type);
    }


    @RequestMapping("/sjsbct")
    @ResponseBody
    public ToJson sjsbct(String userId, Integer gridId, String startTime, String endTime, String eventType,
                         @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                         @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize){
        return gridEventService.sjsbct(userId,gridId,startTime,endTime,eventType,page,pageSize);
    }
    /**
    * @Author 程叶同
    * @Description 排行榜
    * @Date 15:17 2018/1/26
    */
    @RequestMapping("/getEventRankList")
    public BaseWrapper getEventRankList(String rankType, String timeType, String startTime, String endTime){
        return  gridEventService.getEventRankList(rankType,timeType,startTime,endTime);
    }

    /**
    * @Author 程叶同
    * @Description 排行榜 穿透
    * @Date 15:18 2018/1/26
    */
    @RequestMapping("/rankListDetail")
    public BaseWrapper rankListDetail(String rankType, Integer page, Integer pageSize, boolean useFlag, String gridId, String userId, String timeType, String startTime, String endTime){
        return  gridEventService.rankListDetail(rankType,page,pageSize,useFlag,gridId,userId,timeType,startTime,endTime);
    }
    @RequestMapping("/getThreeDetail")
    public BaseWrapper getThreeDetail(Integer page, Integer pageSize, boolean useFlag, String timeType, String gridId, String userId, String startTime, String endTime){
        return  gridEventService.getThreeDetail(page,pageSize,useFlag,timeType,gridId,userId,startTime,endTime);
    }

    /**
     * 页面已办，未办事件进度条
     * @param timeType
     * @return
     */
    @RequestMapping("/tinCount")
    @ResponseBody
    public ToJson tinCount(String timeType){
             return gridEventService.tinCount(timeType);
    }

    /**
     *  页面已办，未办事件列表
     * @param request
     * @param page
     * @param pageSize
     * @param prcsFlag
     * @param parting
     * @return
     */
    @RequestMapping("/selSendOrReceivetuis")
    public BaseWrappers selSendOrReceivetuis(HttpServletRequest request, Integer page, Integer pageSize, Integer prcsFlag, Integer parting, Integer shouji, String timeType){
            return  gridEventService.selSendOrReceivetuis(request,page,pageSize,prcsFlag,parting,shouji,timeType);
    }


    @RequestMapping("/getByTypeByAppearance")
    public BaseWrappers getByTypeByAppearance(HttpServletRequest request) {
        return gridEventService.getByTypeByAppearance(request);
    }

    @RequestMapping("/gridEventTimeByGroup")
    public BaseWrappers gridEventTimeByGroup(HttpServletRequest request) throws ParseException {
        return  gridEventService.gridEventTimeByGroup(request);
    }
    @RequestMapping("/gridEventByRumId")
    public BaseWrappers gridEventByRumId(HttpServletRequest request, int rumId) throws ParseException {
        return  gridEventService.gridEventByRumId(rumId);
    }


}
